import java.util.Vector;


class ICPCP3280_7752 {

    public static void main(String[] args) {
    	int scenario = 1;
    	while (true) {
    		int N = Integer.parseInt(readLn());
    		if (N == 0) break;
    		System.out.println(scenario);
    		process(N);
    		scenario++;
    		
    	}
    	
    }

    private static void process(int N) {
		Word3280[] words = new Word3280[N];
		Vector[] wordsByLetter = new Vector[26];
		
		for (int k = 0; k < 26; k++) {
			wordsByLetter[k] = new Vector();
		}
		
		for (int k = 0; k < N; k++) {
			words[k] = new Word3280(readLn());
			Vector wordsBySpecificLetter = wordsByLetter[words[k].word.charAt(0) - 'a'];
			wordsBySpecificLetter.addElement(words[k]);
		}
		
		for (int k = 0; k < 26; k++) {
			process(wordsByLetter[k], 0, true);
		}
		
		for (int k = 0; k < N; k++) {
			System.out.println(words[k]);
		}
		
	}

	private static void process(Vector vector, int index, boolean b) {
		if (vector.size() == 1) {
			Word3280 word = (Word3280) vector.elementAt(0);
//			System.out.println("if " + word);
			if (b) {
				if (word.abbreviation.length() < word.word.length()) {
					word.abbreviation = word.abbreviation + word.word.charAt(word.abbreviation.length());
				}
			}
		} else {
			b = false;
//			System.out.println("else");
			if (vector.size() > 1) {
//				Word3280[] words = new Word3280[vector.size()];
				Vector[] wordsByLetter = new Vector[26];
				for (int k = 0; k < 26; k++) {
					wordsByLetter[k] = new Vector();
				}
//				System.out.println(index);
//				System.out.println("vector " + vector);
				for (int k = 0; k < vector.size(); k++) {
					Word3280 word = (Word3280) vector.elementAt(k);
//					System.out.println(word);
					if (index < word.word.length()) {
						Vector wordsBySpecificLetter = wordsByLetter[word.word.charAt(index) - 'a'];
//						System.out.println(wordsBySpecificLetter); 
						wordsBySpecificLetter.addElement(word);
						
						if (word.abbreviation.length() < word.word.length()) {
							word.abbreviation = word.abbreviation + word.word.charAt(word.abbreviation.length());
						}
						
					}
				}			
				
				index++;
				for (int k = 0; k < 26; k++) {
//					System.out.println(wordsByLetter[k]);
					process(wordsByLetter[k], index, b);
				}
			}
		}
	}

	private static void process(Vector wordsBySpecificLetter, Word3280 wordToAdd) {
		int size = wordsBySpecificLetter.size();
		
		wordsBySpecificLetter.addElement(wordToAdd);
		
		for (int k = 0; k < size; k++) {
			Word3280 word = (Word3280)wordsBySpecificLetter.elementAt(k);
			if (word.abbreviation.length() < word.word.length()) {
				word.abbreviation = word.abbreviation + word.word.charAt(word.abbreviation.length());
			}
		}
	}

	static String readLn() {
        String newLine = System.getProperty("line.separator");
        StringBuffer buffer = new StringBuffer();
        int car = -1;
        try {
            car = System.in.read();
            while ((car > 0) && (car != newLine.charAt(0))) {
                buffer.append((char)car);
                car = System.in.read();
            }
            if (car == newLine.charAt(0))
            System.in.skip(newLine.length() - 1);
        } catch (java.io.IOException e) { return (null);}
        if ((car < 0) && (buffer.length() == 0)) return (null);
        return (buffer.toString()).trim();
    }

}

class Word3280 {
	
	String word;
	String abbreviation = "";
	
	public Word3280(String word) {
		this.word = word;
	}
	
	public String toString() {
		return word + " " + abbreviation;
	}
}